//
//  ListEditController.m
//  Doc Bao
//
//  Created by Vinh Huynh on 10/2/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ListEditController.h"
#import "News.h"
#import "NewsExtensions.h"
#import "SettingDetailController.h"
#import "EditNewsCellController.h"
#import "EditView.h"
@implementation ListEditController

//@synthesize arrayView;
//@synthesize cell;
@synthesize currentEditView;
/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

-(IBAction) backPressed
{
	[self.navigationController popViewControllerAnimated:YES];
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	arrayView = [[NSMutableArray alloc] init]; 
	NSMutableArray *newsArray = [NSMutableArray arrayWithArray:[News getNews]];
	CGFloat y = 44;
	for (int i = 0; i < [newsArray count]; i++) {
		EditView *newsView = [[[NSBundle mainBundle] loadNibNamed:@"EditView" owner:self options:nil] lastObject];
		newsView.listEditController = self; 
		newsView.index = i;
		News *news = [newsArray objectAtIndex:i];
		[self.view addSubview:newsView];
		[newsView setFrame:CGRectMake(0, y, 320, 50)];
		[newsView.logoImage setImage:[UIImage imageNamed:news.Logo]];
		y = y + 50;
		NSLog(@"y = %f",y);
		[arrayView addObject:newsView];

	}
	newsList = [[NSMutableArray alloc]initWithArray:[News getNews]];
	NSLog(@"%@", arrayView);

}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[arrayView release];
	[newsList release];
    [super dealloc];
}

#pragma mark -
#pragma mark Touch Handle
#define HORIZ_SWIPE_DRAG_MIN 100

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
	NSLog(@"Touch main");
	NSLog(@"index current view %d", self.currentEditView.index);
}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
	//NSLog(@"Touches Moved");
	UITouch *touch = [touches anyObject];
	CGPoint location = [touch locationInView:self.view];
	currentEditView.center = location;
	
	//remove / insert object array / create function loadview / calll loadview  in touchend/
	
}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
	
}


@end
